<route lang="json5" type="page">
{
    layout: "default",
    style: {
        navigationBarTitleText: "登录",
    },
}
</route>

<template>
    <view class="m-login flex flex-col items-center pt-[40rpx]">
        <!-- <view class="w-[140rpx]">
            <image src="/src/static/mp-weixin/images/login.png" mode="widthFix" />
        </view>
        <view class="u-login mt-4 w-[100%]">
            <wd-button block open-type="getUserInfo" @getuserinfo="wxLogin" :custom-style="{ background: '#07c160' }"
                >微信一键登录</wd-button
            > 
        </view>-->
    </view>
</template>

<script lang="ts" setup>
import { wxMaLoginUsingPost } from "@/service/app";
import { useToast } from "wot-design-uni";
import { useUserStore } from "@/store/user";
const userStore = useUserStore();
const toast = useToast();
const invitationId = ref("1924102869944156162");
// 小程序登录
function wxLogin() {
    // if (e.errMsg != "getUserInfo:ok") {
    //     toast.error("授权失败");
    //     return;
    // }
    toast.loading({
        loadingType: "ring",
        msg: "登录中...",
    });
    uni.login({
        provider: "weixin",
        onlyAuthorize: true,
        success: function (res) {
            wxMaLoginUsingPost({ body: { code: res.code, invitationUserId: invitationId.value } }).then((res) => {
                console.log(res);
                toast.close();
                userStore.setToken(res?.data);
                uni.switchTab({
                    url: "/pages/index/index",
                });
            });
        },
    });
}
onLoad((value) => {
    if (decodeURIComponent(value.scene) != "undefined") {
        invitationId.value = decodeURIComponent(value.scene);
    }
    wxLogin();
});
</script>

<style lang="scss" scoped>
.m-login {
    box-sizing: border-box;
    height: 100vh;
    padding: 40rpx 20rpx;
    overflow-y: auto;
    /* background: linear-gradient(135deg, #a1c4fd, #ffffff); */
}
</style>
